package com.sztx.worker_monitor.web.interceptor;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.sztx.worker_monitor.web.handle.LoginHandle;
public class AuthInterceptor extends HandlerInterceptorAdapter {
	
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

		String method = request.getMethod();
		if(method.equalsIgnoreCase("post")) return true;
		
	//	System.out.println("-->preHandle setLoginInfo");
		//System.out.println(".....->ServletContext = "+request.getServletContext().getContextPath());
		
//		System.out.println("-->preHandle setLoginInfo method=" + method+";urI="+request.getRequestURI()+
//				";url="+request.getRequestURL());
		if(LoginHandle.checkLogin() <= 0 ){
			response.setStatus(302);
			response.setHeader("Location", request.getServletContext().getContextPath()+"/monitor/login");
			return false;
		}
		
		return true;

		
	}
	

}